<?php 
	
	namespace app\login\controller;
	use think\Db; // 引用DB类

class Register
{

    // http://127.0.0.1:85/index.php?s=/tdled/test
    /*
    {
        "GDH": "AK1970254",
        "LSM": "002"
    }
	*/
    public function index($data)
    {
		$data1 = json_decode($data, true); // 解析成数组对象
		$data1['register_password']=sha1(md5($data1['register_password']));
		//return $data1['register_phone'];
		//return json($data);
        $phone = Db::table("register")
            ->where("register_phone", $data1['register_phone'])
            ->field("register_phone")
            ->find();
        if($phone){
			return json([
				"data" => 'false',
				'msg' => "该手机号已被注册，请更换手机号",
				'code'=> 406
			]);	
			//return ;
		}else{
			Db::table("register")->insert($data1);
			$inset_login = Db::table("login")
						-> insert([
							"login_name"	=> $data1["register_phone"],
							"login_pass"	=> $data1["register_password"],
							"register_role"	=> 1
						]);
			
			//用户注册成功后，生成用户金额表格，默认用户当前余额为0元
			$inset_balance = Db::table("balance")
						  -> insert([
						  		"user_name"		=> $data1["register_phone"],
						  		"balance_money"	=> 0
						  ]);
			
			//注册成功后，将用户名，qq，微信填入用户信息表
			$insert_user	= Db::table("user")
						   -> insert([
						   		"user_phone"		=> $data1["register_phone"],
						   		"user_name"		=> $data1["register_phone"],
						   		"user_qq"		=> $data1["register_qq"],
						   		"user_wx"		=> $data1["register_wx"],
						   ]);
			//注册成功后，默认用户支付密码为123456
			//$a				=123456;
			$pwd			= sha1(md5(123456));
			$insert_payPwd	= Db::table("paypassword")
						   -> insert([
						   		"user_name"				=> $data1["register_phone"],
						   		"paypassword_paypwd"	=> $pwd,
						   		"paypassword_time"		=> Db::raw("now()")
						   ]);
			
			return json([
				"data" => 'true',
				'msg' => "注册成功",
				'code'=> 200
			]);	
		}
    }
	
	
	
	public function font($data)
    {
		$data1 = json_decode($data, true); // 解析成数组对象
		
		$data1['register_password']=sha1(md5($data1['register_password']));
		//return json($data1);
		//return json($data);
        $phone = Db::table("register_font")
            ->where("register_phone", $data1['register_phone'])
            ->field("register_phone")
            ->find();
        if($phone){
			return json([
				"data" => 'false',
				'msg' => "该手机号已被注册，请更换手机号",
				'code'=> 406
			]);	
			
		}else{
			
			Db::table("register_font")-> insert([
								"register_password"		=> $data1["register_password"],
						   		"register_phone"		=> $data1["register_phone"],
						   		"register_qq"		=> $data1["register_qq"],
						   		"register_wx"		=> $data1["register_wx"],
								"user_wangwang"		=> $data1["user_wangwang"],
						   		"register_checkCode"		=> $data1["register_checkCode"],
						   ]);
			
			$inset_login = Db::table("login_font")
						-> insert([
							"login_name"	=> $data1["register_phone"],
							"login_pass"	=> $data1["register_password"],
							"register_role"	=> 1
						]);
			
			//用户注册成功后，生成用户金额表格，默认用户当前余额为0元
			$inset_balance = Db::table("balance_font")
						  -> insert([
						  		"font_phone"		=> $data1["register_phone"],
								"user_name"		=> $data1["register_phone"],
						  		"font_money"	=> 0
						  ]);
			
			//注册成功后，将用户名，qq，微信填入用户信息表
			$insert_user	= Db::table("user_font")
						   -> insert([
						   		"user_phone"		=> $data1["register_phone"],
						   		"user_name"		=> $data1["register_phone"],
						   		"user_qq"		=> $data1["register_qq"],
						   		"user_wx"		=> $data1["register_wx"],
								"user_wangwang"		=> $data1["user_wangwang"],
						   		"user_province"		=> $data1["province"],
								"user_city"		=> $data1["city"],
						   		"user_area"		=> $data1["area"],
						   ]);
			
			return json([
				"data" => 'true',
				'msg' => "注册成功",
				'code'=> 200
			]);	
		}
    }



    public function read()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) 2018 READ新年快乐</h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }
	
	public function testshamd5()
    {
		
		$str = "中文网";

		echo "MD5的加密结果：".md5($str)."";

		echo "sha1的加密结果：".sha1($str)."";
		
        $GDH = Db::table("test")
            ->where("id", 1)
            ->field("name, age")
            ->find();
        
        return json($GDH);
    }
}
